﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Client_Server_Interface
{
    [Flags]
    public enum PermissionTypes
    {
        None = 0x00,
        LoginToServer = 0x01,
        LoginToClient = 0x02,
        EditServerOptions = 0x04,
        EditClientOptions = 0x08,
        EditDeviceOptions = 0x10,
        //0x20, 0x40, 0x80
        All = 0xFF
    }

    public class PermissionsHelper
    {
        public static PermissionTypes AdminPermissionTypes  = PermissionTypes.All;
        public static PermissionTypes UserPermissionTypes = PermissionTypes.LoginToClient | PermissionTypes.EditClientOptions;

        public static string PermissionsToString(PermissionTypes p)
        {
            return p.ToString();
        }

        public static PermissionTypes PermissionsFromStriong(string p)
        {
            PermissionTypes toRet;
            if (PermissionTypes.TryParse(p, out toRet))
            {
                return toRet;
            }
            return PermissionTypes.None;
        }

        public static bool CheckPermission(PermissionTypes p, PermissionTypes toCheck)
        {
            return (p & toCheck) == toCheck;
        }

    }
}
